package com.wkbb.basic.controller.manage;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.wkbb.basic.model.*;
import com.wkbb.basic.service.*;
import com.wkbb.common.business.BasicBusiness;
import com.wkbb.common.dto.basic.DeviceBoxDto;
import com.wkbb.common.dto.basic.DeviceCameraDto;
import com.wkbb.basic.vo.DeviceTypeManageVo;
import com.wkbb.common.base.BaseController;
import com.wkbb.common.constants.ErrorCode;
import com.wkbb.common.constants.VersionConstant;
import com.wkbb.common.dto.ResultDTO;
import com.wkbb.common.dto.basic.DeviceInfoDto;
import com.wkbb.common.dto.basic.UserDto;
import com.wkbb.common.redis.RedisTemplateUtil;
import com.wkbb.common.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author Lilin
 */
@RestController
@Api(description = "设备信息管理(后台管理)")
@RequestMapping("/basic/{apiVersion}/device/manage")
@Slf4j
public class DeviceManageController extends BaseController {
    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private DeviceInfoService deviceInfoService;

    @Autowired
    private DeviceSerialService deviceSerialService;

    @Autowired
    private DeviceTypeService deviceTypeService;

    @Autowired
    private DeviceCameraService deviceCameraService;

    @Autowired
    private DeviceBoxService deviceBoxService;

    @Autowired
    private WebankUtilService webankUtilService;

    @Autowired
    private OrganizationWebankService organizationWebankService;

    @Autowired
    RedisTemplateUtil redisTemplateUtil;
    
    @ApiOperation(value = "新增设备")
    @RequestMapping(value = "/addDeviceInfo", method = RequestMethod.POST)
    public ResultDTO<Long> addDeviceInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备信息", required = true) @RequestBody DeviceInfo deviceInfo) {

        log.info("***********DeviceInfoManageController.addDeviceInfo******apiVersion:{},deviceInfo:{}", apiVersion, deviceInfo);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (StringUtil.isNullOrBlank(deviceInfo.getDeviceCode()) ||
                    deviceInfo.getOrgId() == null || deviceInfo.getOrgId() == 0 ||
                    deviceInfo.getDeviceTypeId() == null || deviceInfo.getDeviceTypeId() == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            //判断设备是否已存在
            DeviceInfo exists = deviceInfoService.getInfoByDeviceCode(deviceInfo.getDeviceCode());
            if (exists != null) {
                return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
            }

            deviceInfo.setCreateBy(userDto.getName());
            deviceInfo.setUpdateBy(userDto.getName());
            deviceInfoService.insert(deviceInfo);
            return new ResultDTO<>(deviceInfo.getId());
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.addDeviceInfo******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改设备")
    @RequestMapping(value = "/updateDeviceInfo", method = RequestMethod.PUT)
    public ResultDTO<Object> updateDeviceInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备信息", required = true) @RequestBody DeviceInfo deviceInfo) {

        log.info("***********DeviceInfoManageController.updateDeviceInfo******apiVersion:{},deviceInfo:{}", apiVersion, deviceInfo);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        if (deviceInfo.getId() == null || deviceInfo.getId() == 0) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }

        if (deviceInfo.getDeviceCode() != null && deviceInfo.getDeviceCode().isEmpty()) {
            return new ResultDTO<>(ErrorCode.PARAM_MISMATCH);
        }

        try {
            //判断设备是否已存在
            DeviceInfo exists = deviceInfoService.getInfoByDeviceCode(deviceInfo.getDeviceCode());
            if (exists != null && exists.getId() != deviceInfo.getId().longValue()) {
                return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
            }

            deviceInfo.setUpdateBy(userDto.getName());
            ResultDTO<Object> resultDTO = deviceInfoService.update(exists, deviceInfo);
            if(ResultDTO.checkSuccess(resultDTO)) {
                //清缓存
                String deviceRedisKey = BasicBusiness.getDeviceInfoRedisKey(deviceInfo.getDeviceCode());
                redisTemplateUtil.delete(deviceRedisKey);

                return new ResultDTO<>(deviceInfo.getId());
            }else {
                return resultDTO;
            }
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.updateDeviceInfo******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除设备")
    @RequestMapping(value = "/deleteDeviceInfo", method = RequestMethod.DELETE)
    public ResultDTO deleteDeviceInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备表ID", required = true) @RequestParam(name = "id", required = true) List<Long> ids) {

        log.info("***********DeviceInfoManageController.deleteDeviceInfo******apiVersion:{},id:{}", apiVersion, ids);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceInfoService.delete(ids, userDto.getName());

            return new ResultDTO();
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.deleteDeviceInfo******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }


    @ApiOperation(value = "查询设备详情")
    @RequestMapping(value = "/getDeviceInfo", method = RequestMethod.GET)
    public ResultDTO<DeviceInfoDto> getDeviceInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备表ID", required = true) @RequestParam(name = "id", required = true) Long id) {
        log.info("***********DeviceInfoManageController.getDeviceInfo******apiVersion:{},id:{}", apiVersion, id);

        try {
            Map<String, Object> params = new HashMap<>(1);
            params.put("id", id);

            return new ResultDTO<>(deviceInfoService.getDtoByParams(params));
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.getDeviceInfo******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询设备列表")
    @RequestMapping(value = "/getDeviceInfoList", method = RequestMethod.GET)
    public ResultDTO<List<DeviceInfo>> getDeviceInfoList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "设备编号", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode) {
        log.info("***********DeviceInfoManageController.getDeviceInfoList******apiVersion:{},deviceCode:{}", apiVersion, deviceCode);

        try {
            Map<String, Object> params = new HashMap<>(2);
            if (orgId != null && orgId != 0) {
                params.put("orgId", orgId);
            }
            if (!StringUtil.isNullOrBlank(deviceCode)) {
                params.put("deviceCode", deviceCode);
            }

            return new ResultDTO<>(deviceInfoService.getListByMapParams(params));
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.getDeviceInfoList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询设备分页列表")
    @RequestMapping(value = "/getDeviceInfoPageList", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceInfoDto>> getDeviceInfoPageList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "组织名称", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "设备编号", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "设备类型名称", required = false) @RequestParam(name = "deviceTypeName", required = false) String deviceTypeName,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********DeviceInfoManageController.getDeviceInfoPage******apiVersion:{},orgId:{},orgName:{},deviceCode:{}", apiVersion, orgId, orgName, deviceCode);

        try {
            Map<String, Object> params = new HashMap<>(3);
            if (orgId != null && orgId != 0) {
                params.put("orgId", orgId);
            }
            if (!StringUtil.isNullOrBlank(orgName)) {
                params.put("orgName", orgName);
            }
            if (!StringUtil.isNullOrBlank(deviceCode)) {
                params.put("deviceCode", deviceCode);
            }
            if (!StringUtil.isNullOrBlank(deviceTypeName)) {
                params.put("deviceTypeName", deviceTypeName);
            }

            return new ResultDTO<>(deviceInfoService.getDtoPageByParams(params, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.getDeviceInfoPage******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增串口")
    @RequestMapping(value = "/addDeviceSerial", method = RequestMethod.POST)
    public ResultDTO<Long> addDeviceSerial(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "串口详情", required = true) @RequestBody DeviceSerial deviceSerial) {

        log.info("***********DeviceSerialManagerController.addDeviceSerial******apiVersion:{},deviceSerial:{}", apiVersion, deviceSerial);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (StringUtil.isNullOrBlank(deviceSerial.getName())) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            deviceSerial.setCreateBy(userDto.getName());
            deviceSerial.setUpdateBy(userDto.getName());
            deviceSerialService.insert(deviceSerial);
            return new ResultDTO<>(deviceSerial.getId());
        } catch (Exception e) {
            log.error("***********DeviceSerialManagerController.addDeviceSerial******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改串口")
    @RequestMapping(value = "/updateDeviceSerial", method = RequestMethod.PUT)
    public ResultDTO<Long> updateDeviceSerial(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "串口详情", required = true) @RequestBody DeviceSerial deviceSerial) {

        log.info("***********DeviceSerialManagerController.updateDeviceSerial******apiVersion:{},deviceSerial:{}", apiVersion, deviceSerial);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        if (StringUtil.isNullOrBlank(deviceSerial.getName()) || deviceSerial.getId() == null || deviceSerial.getId() == 0) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }

        try {
            deviceSerial.setUpdateBy(userDto.getName());
            deviceSerialService.update(deviceSerial);

            return new ResultDTO<>(deviceSerial.getId());
        } catch (Exception e) {
            log.error("***********DeviceSerialManagerController.updateDeviceSerial******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除串口")
    @RequestMapping(value = "/deleteDeviceSerial", method = RequestMethod.DELETE)
    public ResultDTO deleteDeviceSerial(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "串口表ID", required = true) @RequestParam(name = "id", required = true) Long id) {

        log.info("***********DeviceSerialManagerController.deleteDeviceSerial******apiVersion:{},id:{},updateBy:{}", apiVersion, id);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceSerialService.deleteByPrimaryKey(id);

            return new ResultDTO();
        } catch (Exception e) {
            log.error("***********DeviceSerialManagerController.deleteDeviceSerial******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }


    @ApiOperation(value = "查询串口详情")
    @RequestMapping(value = "/getDeviceSerial", method = RequestMethod.GET)
    public ResultDTO<DeviceSerial> getDeviceSerial(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "串口表ID", required = true) @RequestParam(name = "id", required = true) Long id) {
        log.info("***********DeviceSerialManagerController.getDeviceSerial******apiVersion:{},id:{}", apiVersion, id);

        try {
            return new ResultDTO<>(deviceSerialService.getByPrimaryKey(id));
        } catch (Exception e) {
            log.error("***********DeviceSerialManagerController.getDeviceSerial******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询串口列表")
    @RequestMapping(value = "/getDeviceSerialList", method = RequestMethod.GET)
    public ResultDTO<List<DeviceSerial>> getDeviceSerialList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型表ID", required = true) @RequestParam(name = "deviceTypeId", required = true) String deviceTypeId) {
        log.info("***********DeviceSerialManagerController.getDeviceSerialList******apiVersion:{},deviceTypeId:{}", apiVersion, deviceTypeId);

        try {
            Map<String, Object> params = new HashMap<>(1);
            if (!StringUtil.isNullOrBlank(deviceTypeId)) {
                params.put("deviceTypeId", deviceTypeId);
            }

            return new ResultDTO<>(deviceSerialService.getListByMapParams(params));
        } catch (Exception e) {
            log.error("***********DeviceSerialManagerController.getDeviceSerialList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增类型")
    @RequestMapping(value = "/addDeviceType", method = RequestMethod.POST)
    public ResultDTO<Long> addDeviceType(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型", required = true) @RequestBody DeviceType deviceType) {

        log.info("***********DeviceTypeManageController.addDeviceType******apiVersion:{},deviceType:{}", apiVersion, deviceType);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (StringUtil.isNullOrBlank(deviceType.getName())) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            deviceType.setCreateBy(userDto.getName());
            deviceType.setUpdateBy(userDto.getName());
            deviceTypeService.insert(deviceType);
            return new ResultDTO<>(deviceType.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.addDeviceType******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改类型")
    @RequestMapping(value = "/updateDeviceType", method = RequestMethod.PUT)
    public ResultDTO<Long> updateDeviceType(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型", required = true) @RequestBody DeviceType deviceType) {

        log.info("***********DeviceTypeManageController.updateDeviceType******apiVersion:{},deviceType:{}", apiVersion, deviceType);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        if (StringUtil.isNullOrBlank(deviceType.getName()) || deviceType.getId() == null || deviceType.getId() == 0) {
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }

        try {
            deviceType.setUpdateBy(userDto.getName());
            deviceTypeService.update(deviceType);

            return new ResultDTO<>(deviceType.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.updateDeviceType******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除类型")
    @RequestMapping(value = "/deleteDeviceType", method = RequestMethod.DELETE)
    public ResultDTO deleteDeviceType(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型表ID", required = true) @RequestParam(name = "id", required = true) List<Long> ids) {

        log.info("***********DeviceTypeManageController.deleteDeviceType******apiVersion:{},id:{},updateBy:{}", apiVersion, ids);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceTypeService.delete(ids, userDto.getName());

            return new ResultDTO();
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.deleteDeviceType******", e);
            return new ResultDTO(ErrorCode.SYSTEM_EXCEPTION);
        }
    }


    @ApiOperation(value = "查询设备类型详情")
    @RequestMapping(value = "/getDeviceType", method = RequestMethod.GET)
    public ResultDTO<DeviceTypeManageVo> getDeviceType(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型表ID", required = true) @RequestParam(name = "id", required = true) Long id) {
        log.info("***********DeviceTypeManageController.getDeviceType******apiVersion:{},id:{}", apiVersion, id);

        try {
            return new ResultDTO<>(deviceTypeService.getInfo(id));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceType******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询设备类型列表")
    @RequestMapping(value = "/getDeviceTypeList", method = RequestMethod.GET)
    public ResultDTO<List<DeviceType>> getDeviceTypeList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型名称", required = false) @RequestParam(name = "name", required = false) String name) {
        log.info("***********DeviceTypeManageController.getDeviceTypeList******apiVersion:{},name:{}", apiVersion, name);

        try {
            Map<String, Object> params = new HashMap<>(1);
            if (!StringUtil.isNullOrBlank(name)) {
                params.put("name", name);
            }

            return new ResultDTO<>(deviceTypeService.getListByMapParams(params));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceTypeList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询设备类型分页列表")
    @RequestMapping(value = "/getDeviceTypePageList", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceType>> getDeviceTypePageList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备类型名称", required = false) @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********DeviceTypeManageController.getDeviceTypePageList******apiVersion:{},name:{}", apiVersion, name);

        try {
            Map<String, Object> params = new HashMap<>(1);
            if (!StringUtil.isNullOrBlank(name)) {
                params.put("name", name);
            }

            return new ResultDTO<>(deviceTypeService.getListByPage(params, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceTypePageList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改设备配置信息")
    @RequestMapping(value = "/updateDeviceConfigInfo", method = RequestMethod.PUT)
    public ResultDTO<Long> updateDeviceConfigInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备id集合", required = true) @RequestParam(name = "ids", required = true) List<Long> ids,
            @ApiParam(value = "识别等级", required = false) @RequestParam(name = "level", required = false) Integer level,
            @ApiParam(value = "人脸相似度", required = false) @RequestParam(name = "faceSimilar", required = false) Integer faceSimilar,
            @ApiParam(value = "考勤开关(1默认2打开3关闭)", required = false) @RequestParam(name = "attendanceSwitch", required = false) Short attendanceSwitch) {

        log.info("***********DeviceInfoManageController.updateDeviceConfigInfo******apiVersion:{},ids:{},level:{},faceSimilar:{},attendanceSwitch:{}", apiVersion, ids, level,faceSimilar,attendanceSwitch);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceInfoService.updateDeviceConfigBatch(ids, level, faceSimilar, attendanceSwitch, userDto.getName());
            return new ResultDTO<>();
        } catch (Exception e) {
            log.error("***********DeviceInfoManageController.updateDeviceConfigInfo******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询设备和组织信息列表")
    @RequestMapping(value = "/getDeviceOrgInfoList", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceInfoDto>> getDeviceOrgInfoList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备编号", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "学校名称", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {
        log.info("***********DeviceController.getDeviceOrgInfoList******apiVersion:{},deviceCode:{}", apiVersion);

        try {
            Map<String, Object> parms = new HashMap<>();
            if (!StringUtil.isNullOrBlank(deviceCode)) {
                parms.put("deviceCode", deviceCode);
            }
            if (!StringUtil.isNullOrBlank(orgName)) {
                parms.put("orgName", orgName);
            }
            return new ResultDTO<>(deviceInfoService.getDeviceInfoListByParams(parms, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********DeviceController.getDeviceOrgInfoList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增无感摄像头")
    @RequestMapping(value = "/addDeviceCamera", method = RequestMethod.POST)
    public ResultDTO<Long> addDeviceCamera(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "无感摄像头", required = true) @RequestBody DeviceCamera deviceCamera) {

        log.info("***********DeviceTypeManageController.addDeviceCamera******apiVersion:{},deviceCamera:{}", apiVersion, deviceCamera);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (deviceCamera.getOrgId() == null || deviceCamera.getOrgId() == 0 ||
                    deviceCamera.getScene() == null || deviceCamera.getScene() == 0 ||
                    deviceCamera.getDirection() == null || deviceCamera.getDirection() == 0 ||
                    StringUtil.isNullOrBlank(deviceCamera.getDeviceCode())) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            //检查IPC是否重复添加
            Map<String, Object> params = new HashMap<>(1);
            params.put("deviceCode", deviceCamera.getDeviceCode());
            DeviceCamera existsIpc = deviceCameraService.getByMapParams(params);
            if (existsIpc != null) {
                return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
            }

            deviceCamera.setCreateBy(userDto.getName());
            deviceCamera.setUpdateBy(userDto.getName());
            deviceCameraService.insert(deviceCamera);
            return new ResultDTO<>(deviceCamera.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.addDeviceCamera******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改无感摄像头")
    @RequestMapping(value = "/updateDeviceCamera", method = RequestMethod.PUT)
    public ResultDTO<Long> updateDeviceCamera(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧盒子", required = true) @RequestBody DeviceCamera deviceCamera) {

        log.info("***********DeviceTypeManageController.updateDeviceCamera******apiVersion:{},deviceCamera:{}", apiVersion, deviceCamera);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (deviceCamera.getId() == null || deviceCamera.getId() == 0 ||
                    deviceCamera.getOrgId() == null || deviceCamera.getOrgId() == 0 ||
                    deviceCamera.getScene() == null || deviceCamera.getScene() == 0 ||
                    deviceCamera.getDirection() == null || deviceCamera.getDirection() == 0 ||
                    StringUtil.isNullOrBlank(deviceCamera.getDeviceCode())) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            //检查盒子是否重复添加
            if (!StringUtil.isNullOrBlank(deviceCamera.getDeviceCode())) {
                Map<String, Object> params = new HashMap<>(1);
                params.put("deviceCode", deviceCamera.getDeviceCode());
                DeviceCamera existsIpc = deviceCameraService.getByMapParams(params);
                //修改deviceCode且修改后的deviceCode已存在
                if (existsIpc != null && deviceCamera.getId().longValue() != existsIpc.getId()) {
                    return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
                }
            }

            deviceCamera.setUpdateBy(userDto.getName());
            deviceCameraService.update(deviceCamera);
            return new ResultDTO<>(deviceCamera.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.updateDeviceCamera******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除无感摄像头")
    @RequestMapping(value = "/deleteDeviceCamera", method = RequestMethod.DELETE)
    public ResultDTO deleteDeviceCamera(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "无感摄像头", required = true) @RequestParam(name = "id", required = true) List<Long> ids) {

        log.info("***********DeviceTypeManageController.deleteDeviceCamera******apiVersion:{},ids:{}", apiVersion, Arrays.toString(ids.toArray()));
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceCameraService.deleteCameraBatchByIds(ids);
            return new ResultDTO<>();
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.deleteDeviceCamera******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询无感摄像头详情")
    @RequestMapping(value = "/getDeviceCameraInfo", method = RequestMethod.GET)
    public ResultDTO<DeviceCameraDto> getDeviceCameraInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "无感摄像头ID", required = true) @RequestParam(name = "id", required = true) Long id) {

        log.info("***********DeviceTypeManageController.getDeviceCameraList******apiVersion:{},id:{}",
                apiVersion, id);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceCameraService.getDeviceCameraInfo(id));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceCameraList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询无感摄像头列表")
    @RequestMapping(value = "/getDeviceCameraList", method = RequestMethod.GET)
    public ResultDTO<List<DeviceCameraDto>> getDeviceCameraList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "学校名称(模糊查询)", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "设备编号(模糊查询)", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "名称(模糊查询)", required = false) @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "序列号(模糊查询)", required = false) @RequestParam(name = "serial", required = false) String serial,
            @ApiParam(value = "使用场景", required = false) @RequestParam(name = "scene", required = false) Short scene) {

        log.info("***********DeviceTypeManageController.getDeviceCameraList******apiVersion:{},orgId:{},orgName:{},deviceCode:{},name:{},serial:{},scene:{}",
                apiVersion, orgId, orgName, deviceCode, name, serial, scene);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceCameraService.getDeviceCameraList(orgId, orgName, deviceCode, name, serial, scene));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceCameraList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询无感摄像头分页列表")
    @RequestMapping(value = "/getDeviceCameraPageList", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceCameraDto>> getDeviceCameraPageList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "学校名称(模糊查询)", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "设备编号(模糊查询)", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "名称(模糊查询)", required = false) @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "序列号(模糊查询)", required = false) @RequestParam(name = "serial", required = false) String serial,
            @ApiParam(value = "使用场景", required = false) @RequestParam(name = "scene", required = false) Short scene,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {

        log.info("***********DeviceTypeManageController.getDeviceCameraPageList******apiVersion:{},orgId:{},orgName:{}," +
                        "deviceCode:{},name:{},serial:{},scene:{},pageNo:{},pageSize:{}",
                apiVersion, orgId, orgName, deviceCode, name, serial, scene, pageNo, pageSize);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceCameraService.getDeviceCameraPageList(orgId, orgName, deviceCode, name, serial, scene, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceCameraPageList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "新增智慧盒子")
    @RequestMapping(value = "/addDeviceBox", method = RequestMethod.POST)
    public ResultDTO<Long> addDeviceBox(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧盒子", required = true) @RequestBody DeviceBox deviceBox) {

        log.info("***********DeviceTypeManageController.addDeviceBox******apiVersion:{},deviceCamera:{}", apiVersion, deviceBox);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (deviceBox.getOrgId() == null || deviceBox.getOrgId() == 0 ||
                    StringUtil.isNullOrBlank(deviceBox.getDeviceCode())) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            //检查盒子是否重复添加
            Map<String, Object> params = new HashMap<>(1);
            params.put("deviceCode", deviceBox.getDeviceCode());
            DeviceBox existsBox = deviceBoxService.getByMapParams(params);
            if (existsBox != null) {
                return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
            }

            deviceBox.setCreateBy(userDto.getName());
            deviceBox.setUpdateBy(userDto.getName());
            deviceBoxService.insert(deviceBox);
            return new ResultDTO<>(deviceBox.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.addDeviceBox******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "修改智慧盒子")
    @RequestMapping(value = "/updateDeviceBox", method = RequestMethod.PUT)
    public ResultDTO<Long> updateDeviceBox(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧盒子", required = true) @RequestBody DeviceBox deviceBox) {

        log.info("***********DeviceTypeManageController.updateDeviceBox******apiVersion:{},deviceCamera:{}", apiVersion, deviceBox);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            if (deviceBox.getId() == null || deviceBox.getId() == 0
                    || deviceBox.getOrgId() == null || deviceBox.getOrgId() == 0) {
                return new ResultDTO<>(ErrorCode.PARAM_MISSING);
            }

            //检查盒子是否重复添加
            if (!StringUtil.isNullOrBlank(deviceBox.getDeviceCode())) {
                Map<String, Object> params = new HashMap<>(1);
                params.put("deviceCode", deviceBox.getDeviceCode());
                DeviceBox existsBox = deviceBoxService.getByMapParams(params);
                //修改deviceCode且修改后的deviceCode已存在
                if (existsBox != null && deviceBox.getId().longValue() != existsBox.getId()) {
                    return new ResultDTO<>(ErrorCode.DEVICE_IS_EXIST);
                }
            }

            deviceBox.setUpdateBy(userDto.getName());
            deviceBoxService.update(deviceBox);
            return new ResultDTO<>(deviceBox.getId());
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.updateDeviceBox******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "删除智慧盒子")
    @RequestMapping(value = "/deleteDeviceBox", method = RequestMethod.DELETE)
    public ResultDTO deleteDeviceBox(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧盒子", required = true) @RequestParam(name = "id", required = true) List<Long> ids) {

        log.info("***********DeviceTypeManageController.deleteDeviceBox******apiVersion:{},ids:{}", apiVersion, Arrays.toString(ids.toArray()));
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            deviceBoxService.deleteBoxBatchByIds(ids);
            return new ResultDTO<>();
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.deleteDeviceBox******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询智慧盒子详情")
    @RequestMapping(value = "/getDeviceBoxInfo", method = RequestMethod.GET)
    public ResultDTO<DeviceBoxDto> getDeviceBoxInfo(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "智慧盒子ID", required = true) @RequestParam(name = "id", required = true) Long id) {

        log.info("***********DeviceTypeManageController.getDeviceBoxInfo******apiVersion:{},id:{}",
                apiVersion, id);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceBoxService.getDeviceBoxInfo(id));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceBoxInfo******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询智慧盒子列表")
    @RequestMapping(value = "/getDeviceBoxList", method = RequestMethod.GET)
    public ResultDTO<List<DeviceBoxDto>> getDeviceBoxList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "学校名称(模糊查询)", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "名称(模糊查询)", required = false) @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "设备编号(模糊查询)", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "序列号(模糊查询)", required = false) @RequestParam(name = "deviceSerial", required = false) String deviceSerial,
            @ApiParam(value = "设备MAC地址(模糊查询)", required = false) @RequestParam(name = "deviceMac", required = false) String deviceMac,
            @ApiParam(value = "使用场景", required = false) @RequestParam(name = "scene", required = false) Short scene,
            @ApiParam(value = "是否激活", required = false) @RequestParam(name = "active", required = false) Boolean active) {

        log.info("***********DeviceTypeManageController.getDeviceBoxList******apiVersion:{},orgId:{},orgName:{},name:{},deviceCode:{},deviceSerial:{},deviceMac:{},scene:{},active:{}",
                apiVersion, orgId, orgName, name, deviceCode, deviceSerial, deviceMac, scene, active);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceBoxService.getDeviceBoxList(orgId, orgName, name, deviceCode, deviceSerial, deviceMac, scene, active));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceBoxList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "查询智慧盒子分页列表")
    @RequestMapping(value = "/getDeviceBoxPageList", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceBoxDto>> getDeviceBoxPageList(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "组织ID", required = false) @RequestParam(name = "orgId", required = false) Long orgId,
            @ApiParam(value = "学校名称(模糊查询)", required = false) @RequestParam(name = "orgName", required = false) String orgName,
            @ApiParam(value = "名称(模糊查询)", required = false) @RequestParam(name = "name", required = false) String name,
            @ApiParam(value = "设备编号(模糊查询)", required = false) @RequestParam(name = "deviceCode", required = false) String deviceCode,
            @ApiParam(value = "序列号(模糊查询)", required = false) @RequestParam(name = "deviceSerial", required = false) String deviceSerial,
            @ApiParam(value = "设备MAC地址(模糊查询)", required = false) @RequestParam(name = "deviceMac", required = false) String deviceMac,
            @ApiParam(value = "使用场景", required = false) @RequestParam(name = "scene", required = false) Short scene,
            @ApiParam(value = "是否激活", required = false) @RequestParam(name = "active", required = false) Boolean active,
            @ApiParam(value = "页码", required = true, defaultValue = "1") @RequestParam(name = "pageNo", required = true, defaultValue = "1") Integer pageNo,
            @ApiParam(value = "每页条数", required = true, defaultValue = "10") @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize) {

        log.info("***********DeviceTypeManageController.getDeviceBoxPageList******apiVersion:{},orgId:{},orgName:{},name:{}," +
                        "deviceCode:{},deviceSerial:{},deviceMac:{},scene:{},active:{},pageNo:{},pageSize:{}",
                apiVersion, orgId, orgName, name, deviceCode, deviceSerial, deviceMac, scene, active, pageNo, pageSize);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            return new ResultDTO<>(deviceBoxService.getDeviceBoxPageList(orgId, orgName, name, deviceCode, deviceSerial, deviceMac, scene, active, pageNo, pageSize));
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceBoxPageList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }

    @ApiOperation(value = "激活智慧盒子（同步用户人脸数据）")
    @RequestMapping(value = "/activeDeviceBox", method = RequestMethod.GET)
    public ResultDTO<PageInfo<DeviceBoxDto>> updateDeviceBoxActive(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "设备ID", required = true, defaultValue = "3") @RequestParam(name = "id", required = true) List<Long> ids,
            @ApiParam(value = "激活状态", required = true, defaultValue = "true") @RequestParam(name = "active", required = true) Boolean active) {
        log.info("***********DeviceTypeManageController.updateDeviceBoxActive******apiVersion:{},ids:{},active:{}",
                apiVersion, ids, active);
        UserDto userDto = getUserByLogin();
        if (userDto == null) {
            return new ResultDTO<>(ErrorCode.USER_NOT_EXIST);
        }

        try {
            for (long id : ids) {
                //检查设备是否存在
                DeviceBox deviceBox = deviceBoxService.getByPrimaryKey(id);
                if (deviceBox == null) {
                    return new ResultDTO<>(ErrorCode.DEVICE_NOT_EXISTS);
                }

                //必须要盒子在线的时候才能激活
                if (!deviceBoxService.updateBoxActive(userDto.getName(), deviceBox, active)) {
                    return new ResultDTO<>(ErrorCode.JVT_BOX_OFFLINE);
                }
            }
            return new ResultDTO<>();
        } catch (Exception e) {
            log.error("***********DeviceTypeManageController.getDeviceBoxPageList******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }
    @ApiOperation(value = "批量修改设备信息到微众系统")
    @RequestMapping(value = "/batchModifyDevice", method = RequestMethod.POST)
    public ResultDTO<Object> batchModifyDevice(
            @ApiParam(value = "接口版本", required = true, defaultValue = VersionConstant.V1) @PathVariable(value = "apiVersion", required = true) String apiVersion,
            @ApiParam(value = "机构id字符串(deviceCodes和orgids两个字段必须传一个)", required = false) @RequestParam(name = "orgids", required = false) String orgids,
            @ApiParam(value = "设备code字符串(deviceCodes和orgids两个字段必须传一个)", required = false) @RequestParam(name = "deviceCodes", required = false) String deviceCodes,
            @ApiParam(value = "摄像头类型，0:红外双目 1:单目", required = false) @RequestParam(name = "cameraType", required = false)  Integer cameraType,
            @ApiParam(value = "活体开关，0:关闭 1:开启 1) 如果摄像头类型是“红外双目”，则该开关设置的是“红外活体开关” 2) 如果摄像头类型是“1 单目”，则该开关是设置“翻拍活体开关” 3) 如果不传值，则默认红外活体开，翻拍活体关", required = false) @RequestParam(name = "cameraTypeSwitch", required = false)   Integer cameraTypeSwitch
    ) {
        log.info("***********WebankController.batchModifyDevice******apiVersion:{},orgids:{},cameraType:{}，deviceCodes{}",
                apiVersion, orgids,cameraType,deviceCodes);
        if(StringUtil.isEmptyIgnoreBlank(orgids) && StringUtil.isEmptyIgnoreBlank(deviceCodes)){
            return new ResultDTO<>(ErrorCode.PARAM_MISSING);
        }
        try {
            if(!StringUtil.isEmptyIgnoreBlank(deviceCodes)) {
                String[] deviceCodeArray = deviceCodes.split(",");
                for(String deviceCode: deviceCodeArray) {
                    DeviceInfo deviceInfo = deviceInfoService.getInfoByDeviceCode(deviceCode);
                    OrganizationWebank organizationWebank = organizationWebankService.getOrganizationWebanksByOrgId(deviceInfo.getOrgId(),null);
                    webankUtilService.batchModifyDevice(deviceInfo.getDeviceSerial(), cameraType, cameraTypeSwitch, true, organizationWebank.getWebankAppid(), organizationWebank.getWebankSecret(), organizationWebank.getOrgId());
                    log.info("批量修改设备信息，deviceCode:{}，cameraType:{}，organizationWebank:{}", deviceCode,cameraType, JSONObject.toJSONString(organizationWebank));
                }
            }else  if(!StringUtil.isEmptyIgnoreBlank(orgids)) {
                String[] orgidArray = orgids.split(",");
                for(String orgId: orgidArray) {
                    Map<String, Object> params = new HashMap<>(1);
                    if (orgId != null && !orgId.equals("0")) {
                        params.put("orgId", orgId);

                        OrganizationWebank organizationWebank = organizationWebankService.getOrganizationWebanksByOrgId(Long.parseLong(orgId),null);

                        List<DeviceInfo> deviceInfoList = deviceInfoService.getListByMapParams(params);
                        deviceInfoList.forEach(deviceInfo -> {
                            webankUtilService.batchModifyDevice(deviceInfo.getDeviceSerial(), cameraType,  cameraTypeSwitch, true, organizationWebank.getWebankAppid(), organizationWebank.getWebankSecret(), organizationWebank.getOrgId());
                            log.info("批量修改设备信息，deviceCode:{}，cameraType:{}，organizationWebank:{}", deviceInfo.getDeviceCode(),cameraType, JSONObject.toJSONString(organizationWebank));
                        });
                    }
                }
            }
            return new ResultDTO<>();
        } catch (Exception e) {
            log.error("***********DeviceController.batchModifyDevice******", e);
            return new ResultDTO<>(ErrorCode.SYSTEM_EXCEPTION);
        }
    }
}
